package com.weixin.dao.impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.weixin.dao.IUsersDAO;
import com.weixin.util.C3p0Util;
import com.weixin.vo.Kiting;
import com.weixin.vo.Users;

public class UserImpl implements IUsersDAO {


	@Override
	public Users findById(String name, String pwd) throws SQLException {
		return C3p0Util.qr.query("select * \r\n" + 
				"from user_table \r\n" + 
				"left join bank_table\r\n" + 
				"on user_table.bank_id=bank_table.bank_id\r\n" + 
				"where user_name=? and user_pwd=?", new BeanHandler<Users>(Users.class), name, pwd);
	}

	@Override
	public boolean update(Users vo) throws SQLException {
		boolean b = C3p0Util.qr.execute(" update user_table set user_money = ? where user_name=? and user_pwd=?",vo.getUser_money(),vo.getUser_name(),vo.getUser_pwd() )>0;
		return b;
	}

	@Override
	public boolean insert(Kiting vo) throws SQLException {
		boolean b =  C3p0Util.qr.execute("insert into kiting_table(user_name,bank_name,user_cardNo,money,user_money) values(?,?,?,?,?)", vo.getUser_name(),vo.getBank_name(),vo.getUser_cardNo(),vo.getMoney(),vo.getUser_money())>0;
		return b;
	}

	@Override
	public Users findByName(String name, String pwd) throws SQLException {
		return C3p0Util.qr.query("select * from user_table where user_name=? and user_pwd=?", new BeanHandler<Users>(Users.class),name,pwd);
	}
	
	
	
}
